package main

import (
	"fmt"
	"strconv"
)

var capChan = 2
var chans = make(chan map[string]bool, capChan)

func main() {
	var map1 = make(map[string]bool, 1)
	map1["a"] = true
	map1["b"] = true
	map1["c"] = true
	map1["d"] = true
	fmt.Println(map1)
	go count("son", 5)
	go count("daughter", 8)
	for {
		if len(chans) == capChan {
			break
		}
	}
	close(chans) // chan被读之前如果不close，会一直读下去
	for {
		map2, ok := <-chans
		if ok == false {
			break
		}
		fmt.Println(map2)
	}
}

func count(name string, n int) {
	for i := 0; i < n; i++ {
		fmt.Println(name + strconv.Itoa(i))
	}
	chans <- map[string]bool{name: true}
}
